
package edu.hawaii.webspider;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import org.junit.Test;

/**
 * Tests the WebSpider class.
 * @author Ben
 *
 */

public class TestWebSpider {

  private final Integer numLinks = Integer.valueOf(26);
  /**
   * Tests basic operation of the webspider.
   * @exception Exception if getNumLinks throws an exception.
   */

  @Test
  public void testBasicOperation() throws Exception {
    WebSpider workingSpider = new WebSpider("http://www.httpunit.org");
      assertEquals("testing getNumLinks.", numLinks.intValue(), 
        workingSpider.getNumLinks("http://www.httpunit.org"));  
      
  }
  
  /**
   * Tests that methods throw the correct exceptions.
   */

  @Test
  public void testException() {
    WebSpider badSpider = new WebSpider("http://");
    try {
      badSpider.getNumLinks("http://");
      fail("Did not throw exception");
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
  
  /**
   * Tests the main method of the WebSpider class (with the -totallinks option).
   */
  @Test
  public void testTotalLinks() {
    String[] args = {"-totallinks","http://www.hackystat.org","10"};
    try {
      WebSpider.main(args);
    }
    catch (Exception e) {
      fail("Unhandled exception for main");
    }
  }
  
  /**
   * Tests the main method of the WebSpider class (with the -mostpopular option).
   */
  @Test
  public void testMostPopular() {
    String[] args = {"-mostpopular","http://www.hackystat.org","10"};
    try {
      WebSpider.main(args);
    }
    catch (Exception e) {
      fail("Unhandled exception for main");
    }
  }
  /*
  @Test
  public void testBogusInput() {
    String[] args = {"-badcommand", "", ""};
    try {
      WebSpider.main(args);
    }
    catch (Exception e) {
      fail("Unhandled exception for main");
    }
  }
  */
}
